$(function () {
    getUserList();
});
/*重置*/
function resetClick(){
    $(".dis-inebl input").val("");
    $("#orderPayState option:selected").text("全部");
    getUserList();
}
/*查询*/
function getUserList(init){
    JY.Model.loading();
	$("#ticktTable tbody").html("");
    var pageNum=$("#baseForm .pageNum").val();
    var pageSize=$("#baseForm .pageSize").val();
    var orderPayState=$("#orderPayState option:selected").val();
    if($("#orderPayState option:selected").text()=="全部"){
        orderPayState="";
    }
	$.ajax({
		url : jypath + "/oder/getAllYmOrder",
		type : "get",
		data:{
            "pageNum":pageNum,
            "pageSize":pageSize,
            "orderPayState":orderPayState,
		},
		jsonType : "json",
		success : function(data) {
		    console.log(data)
            console.log("获取订单返回信息")
            var data=data instanceof Object ? data : JSON.parse(data);
            var html="";
            var list=data.obj;
            var results=list.results;
            var pageNum=list.pageNum,
                pageSize=list.pageSize,
                totalRecord=list.totalRecord;
           if(results!=null&&results.length>0){
                var leng=(pageNum-1)*pageSize;//计算序号
                for(var i = 0;i<results.length;i++){
                    var l=results[i];
                    html+="<tr class='tr_color'>";
                    html+="<td class='center ver-m'><label><input type='checkbox' name='ids' value='"+l.orderId+"' class='ace' /> <span class='lbl'></span></label></td>";
                    html+="<td class='center'>"+l.outTradeNo+"</td>";
                    html+="<td class='center'>"+l.nickName+"</td>";
                    var totalCost=(l.totalCost*0.01).toFixed(2);
                    html+="<td class='center'>"+totalCost+"</td>";
                    if(l.orderName==null || l.orderName ==""){
                        html+="<td class='center'>无</td>";
                    }else{
                        html+="<td class='center'>"+l.orderName+"</td>";
                    }
                    if(l.orderPhone==null || l.orderPhone ==""){
                        html+="<td class='center'>无</td>";
                    }else{
                        html+="<td class='center'>"+l.orderPhone+"</td>";
                    }
                    if(l.orderPayState==1){
                        html+="<td class='center'>待支付</td>";
                    }else if(l.orderPayState==2){
                        html+="<td class='center'>已支付</td>";
                    }else if(l.orderPayState==3){
                        html+="<td class='center'>退款</td>";
                    }else if(l.orderPayState==4){
                        html+="<td class='center'>取消</td>";
                    }
                    html+="<td class='center'>"+l.orderPayWay+"</td>";
                    html+="</tr>";
                }
                $("#ticktTable tbody").append(html);
                JY.Page.setPage("baseForm","pageing",pageSize,pageNum,totalRecord,"getUserList");
            }else{
                html+="<tr><td colspan='8' class='center'>没有相关数据</td></tr>";
                $("#ticktTable tbody").append(html);
                $("#baseForm ul").empty();//清空分页
            }
            JY.Model.loadingClose();
		}
	})
}
// 查看详情
function checkClick(){
    clearData();
    var chks =[];
    $('#ticktTable input[name="ids"]:checked').each(function(){
        chks.push($(this).val());
    });
    if(chks.length==0) {
        JY.Model.info("您没有选择任何内容!");
    }else if(chks.length==1){
        console.log(chks[0])
        $.ajax({
            url : jypath + "/oder/getOrderGoodsByOrderId",
            type : "get",
            data:{
                "orderId":chks[0],
            },
            jsonType : "json",
            success : function(data) {
                console.log(data);
                var html="";
                if(data.obj.length>0){
                    for(var i=0;i<data.obj.length;i++){
                        var l=data.obj[i];
                        html+="<tr>"
                        html+="<td class='center'>"+l.goodsName+"</td>"
                        html+="<td class='center'>"+l.goodsType+"</td>"
                        var goodsPrice=(l.goodsPrice*0.01).toFixed(2)
                        html+="<td class='center'>"+goodsPrice+"</td>"
                        html+="<td class='center'>"+l.goodsNumber+"</td>"
                        html+="</tr>"
                    }
                    $("#generateForm tbody").append(html);
                }
            }
        })
        JY.Model.check("auForm_edit","查看详情",function(){

        });
    }else{
        JY.Model.info("您只能选择一条进行操作!");
    }
}
function clearData(){
    $("#generateForm input").val("");
    $("#groomsSel").find("option[value = '1']").prop("selected","selected");

}
